package shiyl.scaffold;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
@EnableDiscoveryClient
@Slf4j
public class DemoServiceApplication {

    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext context = SpringApplication.run(DemoServiceApplication.class, args);
        showNacosProperties(context) ;
    }

    private static void showNacosProperties(ConfigurableApplicationContext context) throws InterruptedException {
        while(true) {
            //当动态配置刷新时，会更新到 Enviroment中，因此这里每隔一秒中从Enviroment中获取配置
            String who = context.getEnvironment().getProperty("demo.who");
            String name = context.getEnvironment().getProperty("demo.name");
            String age = context.getEnvironment().getProperty("demo.age");
            String bValue = context.getEnvironment().getProperty("demo.local.bootstrap.value");
            String aValue = context.getEnvironment().getProperty("demo.application.yaml.value");

            log.info(" who {}, name {}, age {} , bValue {}, aValue {}", who,name, age,bValue,aValue);

            TimeUnit.SECONDS.sleep(5);
        }
    }
}
